package com.xinruke.hostels.reservation.service;

import com.xinruke.hostels.central.manage.interfaces.api.CentralManageAPI;
import com.xinruke.hostels.central.manage.interfaces.dto.HotelInfoDetailQueryDTO;
import com.xinruke.hostels.central.manage.interfaces.dto.HotelInfoDetailQueryResultDTO;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.dailymanage.interfaces.api.DailyManageApi;
import com.xinruke.hostels.dailymanage.interfaces.dto.CommentAverageResultDto;
import com.xinruke.hostels.reservation.interfaces.dto.ReservationHotelDetailQueryResultDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author GuoZheng
 * @ClassName HotelService
 * @date：2019/6/23
 * @version: V1.0.0
 * @description：
 */
@Service
public class ReservationHotelService {
    @Resource
    private DailyManageApi dailyManageApi;
    @Resource
    private CentralManageAPI centralManageAPI;

    public ResultVO<ReservationHotelDetailQueryResultDTO> getHotelInfoDtail(HotelInfoDetailQueryDTO hotelInfoQueryDTO) {
        ResultVO<ReservationHotelDetailQueryResultDTO> resultVO = ResultVO.fail();
        ReservationHotelDetailQueryResultDTO dataDTO = new ReservationHotelDetailQueryResultDTO();
        ResultVO<HotelInfoDetailQueryResultDTO> hotelInfoDtail = centralManageAPI.getHotelInfoDtail(hotelInfoQueryDTO);
        if (hotelInfoDtail.getCode() == ResultVO.FAIL) {
            resultVO.setMessage("服务调用失败");
            return resultVO;
        }
        BeanUtils.copyProperties(hotelInfoDtail.getData(), dataDTO);
        CommentAverageResultDto average = dailyManageApi.average(dataDTO.getId());
        dataDTO.setAverageScore(average.getScore());
        dataDTO.setAverageScoreMingcheng(average.getDescribe());
        BeanUtils.copyProperties(hotelInfoDtail, resultVO);

        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        resultVO.setData(dataDTO);
        return resultVO;
    }

}
